Passed
Push — master ( deb1f6...0e29a7 )
by Mathieu
02:21 queued 35s
created

Project.getId   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
2
import { Customer } from '../Customer/Customer.entity';
3
4
export enum InvoiceUnits {
5
  DAY = 'day',
6
  HOUR = 'hour'
7
}
8
9
@Entity()
10
export class Project {
11
  @PrimaryGeneratedColumn('uuid')
12
  private id: string;
13
14
  @Column({ type: 'varchar', nullable: false })
15
  private name: string;
16
17
  @Column('enum', { enum: InvoiceUnits, nullable: false })
18
  private invoiceUnit: InvoiceUnits;
19
20
  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
21
  private createdAt: Date;
22
23
  @ManyToOne(type => Customer, { nullable: false, onDelete: 'CASCADE' })
24
  private customer: Customer;
25
26
  constructor(
27
    name: string,
28
    invoiceUnit: InvoiceUnits,
29
    customer: Customer
30
  ) {
31
    this.name = name;
32
    this.invoiceUnit = invoiceUnit;
33
    this.customer = customer;
34
  }
35
36
  public getId(): string {
37
    return this.id;
38
  }
39
40
  public getName(): string {
41
    return this.name;
42
  }
43
44
  public getInvoiceUnit(): InvoiceUnits {
45
    return this.invoiceUnit;
46
  }
47
48
  public getCreatedAt(): Date {
49
    return this.createdAt;
50
  }
51
52
  public getCustomer(): Customer {
53
    return this.customer;
54
  }
55
56
  public getFullName(): string {
57
    return `[${this.customer.getName()}] ${this.getName()}`;
58
  }
59
60
  public update(
61
    customer: Customer,
62
    invoiceUnit: InvoiceUnits,
63
    name: string
64
  ): void {
65
    this.customer = customer;
66
    this.invoiceUnit = invoiceUnit;
67
    this.name = name;
68
  }
69
}
70